<script setup lang="ts">
definePageMeta({ layout: "admin" });
import * as XLSX from "xlsx";

const tableData = reactive({ data: [] });

$api("/getAddress").then((res: any) => {
  console.log(res);
  tableData.data = res;
});

const exportExcel = () => {
  const data = XLSX.utils.json_to_sheet(tableData.data);
  const wb = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, data, "test-data");
  XLSX.writeFile(wb, "test.xlsx");
};

onMounted(async () => {});
</script>

<template>
  <AdminContainer>
    <template #header> </template>
    <div>
      <el-button @click="exportExcel()">导出数据报告</el-button>
      <el-table :data="tableData.data" style="width: 100%">
        <el-table-column prop="_id" label="id" width="180" />
        <el-table-column prop="userId" label="用户 ID" width="180" />
        <el-table-column prop="address" label="地址" />
        <el-table-column prop="phone" label="电话" />
        <el-table-column prop="name" label="名称" />
        <el-table-column prop="flag" label="状态" />
        <el-table-column prop="date" label="日期" />
      </el-table>
    </div>
    <template #footer> </template>
  </AdminContainer>
</template>
